﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace KwaiXiaoDian.Common
{
    public class KwaiXiaoDianHelper
    {
        /// <summary>
        /// 生成随机用户密码
        /// </summary>
        /// <returns></returns>
        public static string GenerateUserPassword()
        {
            var random = new Random();
            var capital = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            var letters = "abcdefghijklmnopqrstuvwxyz";
            var character = "~!@#$%^.&*/_+-|:?";

            var pwdSrcs = new IEnumerable<char>[] {
                Enumerable.Range(0,3).Select(u => random.Next(0,9).ToString()[0]),
                Enumerable.Range(0,3).Select(u => letters[ random.Next(0,letters.Length) ]),
                Enumerable.Range(0,3).Select(u => character[ random.Next(0,character.Length) ]),
                Enumerable.Range(0,3).Select(u => capital[ random.Next(0,capital.Length) ]),
            };

            var pwds = pwdSrcs.SelectMany(u => u).ToArray();
            for (int i = 0; i < pwds.Length; i++)
            {
                var t = pwds[i];
                var r = random.Next(0, pwds.Length);
                pwds[i] = pwds[r];
                pwds[r] = t;
            }
            var pwd = string.Format("{0}{1}{2}", capital[random.Next(0, capital.Length)], string.Concat(pwds), capital[random.Next(0, capital.Length)]);
            return pwd;
        }


    }
}
